package com.mc.lp.database.service.handler.util;


/**
 * 
 * @author deepak
 * contains aggregated grades
 */
public class AggregatedGrades {
	int gradeId;
	Long subjectId;
	int weightage;
	int totalTerm;
	int position;
	public int getGradeId() {
		return gradeId;
	}
	public void setGradeId(int gradeId) {
		this.gradeId = gradeId;
	}
	
	public Long getSubjectId() {
		return subjectId;
	}
	public void setSubjectId(Long subjectId) {
		this.subjectId = subjectId;
	}
	public int getWeightage() {
		return weightage;
	}
	public void setWeightage(int weightage) {
		//greater than zero is most important
		if(weightage>0)
		totalTerm++;
		
		this.weightage = weightage;
	}
	
	public int getAverageWeightage(){
		if(totalTerm==0)
			return 0;
		return Math.round(this.weightage / totalTerm)*1;
	}
	
	
	public int getTotalTerm() {
		return totalTerm;
	}
	public void setTotalTerm(int totalTerm) {
		this.totalTerm = totalTerm;
	}
	public int getPosition() {
		return position;
	}
	public void setPosition(int position) {
		this.position = position;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if(obj != null && obj instanceof AggregatedGrades){
			AggregatedGrades comingObject= (AggregatedGrades)obj;
				if(comingObject.getGradeId() == this.gradeId && comingObject.getSubjectId()== this.subjectId){
					return true;
				}else{
					return false;
				}
		}else{
			return false;
		}
	}
	
	@Override
	public int hashCode() {
		return (int) (gradeId * 7 + ((subjectId==null)?0:subjectId*7));
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "[Grade Id: "+this.gradeId+", Subject Id: "+this.subjectId+", Weightage:"+this.weightage+"]";
	}
}
